package com.juzi.string;

public class StringAPIOtherDemo5 {
    public static void main(String[] args) {

//        public int length()                                                         返回此字符串的长度
        String name = "我爱中国love";
        System.out.println(name);
        System.out.println(name.length());

//        public char charAt(int index)                                               获取某个索引位置处的字符
        char c = name.charAt(1);
        System.out.println(c);

        System.out.println("-------------遍历字符串中的每个字符------------");
        for (int i = 0; i < name.length(); i++) {
            char ch = name.charAt(i);
            System.out.println(ch);
        }

//        public char[] toCharArray()                                                 将当前字符串转换成字符数组返回
        char[] chars = name.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char ch = chars[i];
            System.out.println(ch);
        }

//        public String substring(int beginIndex, int endIndex) 	                  根据开始和结束索引进行"截取"，得到新的字符串（包前不包后）
        String name2 = "java是最厉害的编程语言!";
        System.out.println(name2);
        String rs = name2.substring(0,9);
        System.out.println(rs);

//        public String substring(int beginIndex) 	                                  从传入的索引处截取，截取到末尾，得到新的字符串
        String rs2 = name2.substring(9);
        System.out.println(rs2);

//        public String replace(CharSequence target, CharSequence replacement)    	  使用新值，将字符串中的旧值替换，得到新的字符串
        String name3 = "我屮，这么牛逼？好屌哦，你个傻逼。";
        String rs3 = name3.replace("逼","*");
        System.out.println(rs3);

//        public boolean contains(CharSequence s)                精准判断有没有
        System.out.println(name3.contains("逼"));  //true
        System.out.println(name3.contains("妈"));  //false

//        public boolean startsWith(String prefix)               精准判断开始
        System.out.println(name3.startsWith("我屮"));//true
        System.out.println(name3.startsWith("我*"));//false

//        public String[] split(String regex) 	                                      根据传入的规则切割字符串，得到字符串数组返回
        String name4 = "周慧敏,李嘉欣,朱茵";
        String[] names = name4.split(",");
        for (int i = 0; i < names.length; i++) {
            System.out.println("选择了:" + names[i]);
        }

    }
}
